package com.leyou.cat.controller;

import com.leyou.cat.entity.Cart;
import com.leyou.cat.service.CartService;
import com.leyou.common.bean.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zqq
 * @ClassName CartController
 * @Description
 * @date 2020/3/10-15:26
 */
@Api(value = "CartController", description = "购物车相关接口")
@RestController
public class CartController {

    @Autowired
    private CartService cartService;

    @PostMapping("add")
    @ApiOperation(value = "添加购物车", notes = "添加购物车")
    public Result addCart(@RequestBody Cart cart) {
        return this.cartService.addCart(cart);
    }

    @GetMapping("query")
    @ApiOperation(value = "查询购物车列表", notes = "查询购物车列表")
    public Result<List<Cart>> queryCartList() {
        return this.cartService.queryCartList();
    }

    @PutMapping("update")
    @ApiOperation(value = "修改购物车", notes = "修改购物车")
    public Result updateNum(@RequestBody Cart cart){
        return this.cartService.updateCarts(cart);
    }

    @DeleteMapping("delete/{skuId}")
    @ApiOperation(value = "删除购物车", notes = "删除购物车")
    public Result deleteCart(@ApiParam(name = "skuId",value = "商品id",required = true) @PathVariable("skuId") String skuId) {
        return this.cartService.deleteCart(skuId);
    }

    @PostMapping("merge")
    @ApiOperation(value = "合并购物车", notes = "合并购物车")
    public Result mergeCart(@RequestBody List<Cart> list) {
        return this.cartService.mergeCart(list);
    }

}
